package com.ph.shopping.facade.pay.service.impl.gzylcash;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.ph.shopping.common.core.base.BaseService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.ph.shopping.common.core.customenum.TransCodeEnum;
import com.ph.shopping.common.util.result.Result;
import com.ph.shopping.facade.mapper.MemberDrawcashRecordMapper;
import com.ph.shopping.facade.mapper.MemberScoreMapper;
import com.ph.shopping.facade.mapper.ScoreCostTradeMapper;
import com.ph.shopping.facade.mapper.ScoreIncomeTradeMapper;
import com.ph.shopping.facade.mapper.ScoreTotalTradeMapper;
import com.ph.shopping.facade.pay.bean.BodyInfo;
import com.ph.shopping.facade.pay.entity.MemberDrawcashRecord;
import com.ph.shopping.facade.pay.entity.MemberScore;
import com.ph.shopping.facade.pay.entity.ScoreCostTrade;
import com.ph.shopping.facade.pay.entity.ScoreIncomeTrade;
import com.ph.shopping.facade.pay.entity.ScoreTotalTrade;
import com.ph.shopping.facade.pay.service.gzylcash.GZYLCashService;
import com.ph.shopping.facade.pay.utils.gzyl.HttpUtils;
import com.ph.shopping.facade.pay.utils.gzyl.PayConfig;
import com.ph.shopping.facade.pay.utils.gzyl.SignUtils;
import com.ph.shopping.facade.pay.utils.gzyl.SystemRetCode;
import com.ph.shopping.facade.pay.utils.gzyl.SystemRetField;

/**
 *
 * @author 黄鑫
 * @e-mail abc12707058@hotmail.com
 * @version v1.0
 * @copyright 2010-2015
 * @create-time 2017年2月6日 上午9:33:39
 * 
 */
@Component
@Service(version="1.0.0")
public class GZYLCashServiceImpl extends BaseService implements GZYLCashService {
	
	private static Log logger = LogFactory.getLog(GZYLCashServiceImpl.class);

	@Autowired
	private MemberDrawcashRecordMapper memberDrawcashRecordMapper;//提现记录

	@Autowired
	private MemberScoreMapper memberScoreMapper;//会员积分基础表
	@Autowired
	private ScoreIncomeTradeMapper scoreIncomeTradeMapper;//会员积分增加记录表
	@Autowired
	private ScoreCostTradeMapper scoreCostTradeMapper;//会员积分消费记录表
	@Autowired
	private ScoreTotalTradeMapper scoreTotalTradeMapper;//会员积分记录总表
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public Result defrayPay(BodyInfo bodyInfo, String sessionRole) {
		JSONObject jsonParam = new JSONObject();
		Result appResult = new Result();
		/****************数据补全*********************/
        jsonParam.put("custOrderId", bodyInfo.getMerOrderNo()); // 客户的订单号
        jsonParam.put("partnerFlowNum", bodyInfo.getPartnerFlowNum()); // 流水号  这个需要重新获取并添加到数据库中（一般为时间戳）
//        crs.setMoney(crs.getMoney()-50000); //提交银行时 减5元手续费(维护提现记录时要加上5元)
        //jsonParam.put("payeeOpenBankId", "313701098010");  // 收款方开会银行（对公必填，对私可不填）
		BigDecimal amount = BigDecimal.valueOf(Double.parseDouble(bodyInfo.getAmount().trim()));
		int bankmoney = amount.intValue();
		int scaleDouble = bankmoney/100;
        jsonParam.put("orderAmount", scaleDouble); // 代付金额（单位：分）//测试提现
        jsonParam.put("payeeAcctNum", bodyInfo.getAccNo());//（代付）收款方账号
        jsonParam.put("payeeAcctType", PayConfig.payeeAcctType); //PERSONAL 对私 ， BUSINESS 对公
        jsonParam.put("remarks", "提现操作");             // 备注
//        crs.setMoney(crs.getMoney()+50000);
        jsonParam.put("payeeAcctName", bodyInfo.getAccName());  // 收款方户名
//        jsonParam.put("custId", PayConfig.test_custId);//客户号 云平台提供，云平台唯一编号，在云平台注册成功后，登陆云平台即可查询到。 
//        jsonParam.put("partnerId", PayConfig.test_partnerId);// 合作渠道ID
//        jsonParam.put("notifyUrl",PayConfig.test_notifyUrl);
//        String url = PayConfig.test_guiyangJSBUrl;
        jsonParam.put("custId", PayConfig.custId);//客户号 云平台提供，云平台唯一编号，在云平台注册成功后，登陆云平台即可查询到。 
        jsonParam.put("partnerId", PayConfig.partnerId);// 合作渠道ID
        jsonParam.put("notifyUrl",PayConfig.notifyUrl); //异步通知地址
        String url = PayConfig.guiyangJSBUrl;
        try {
            // 参数转换为FastJson对象，便于操作。
            String sign = "no_sign";
            // 签名建议   私钥
            //String privateKey = PayConfig.privateKey;
            String privateKey = PayConfig.privateKey;
            sign = SignUtils.signBySoft(privateKey, SignUtils.getSignData(jsonParam)); // 加密
            jsonParam.put("sign", sign);
        
            // 执行请求
            String reqMsgHasSign = jsonParam.toJSONString();
            System.out.println("代付请求报文：" + reqMsgHasSign);
            logger.info("代付请求报文：" + reqMsgHasSign);
            String respStr = HttpUtils.execute(url, reqMsgHasSign, 60000);
            System.out.println("代付响应报文：" + respStr);
            logger.info("代付响应报文：" + respStr);

            JSONObject respJson = JSONObject.parseObject(respStr);
            if (!SystemRetCode.SUCCESS.toString().equalsIgnoreCase(respJson.getString(SystemRetField.RET_CODE.toString()))) {
            	logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+"通讯异常，请查看日志");
				appResult.setCode("1");
				appResult.setMessage("FALL");
            	return appResult;
            }
            // 解析返回的json串，验签
            String respParamsStr = respJson.getString(SystemRetField.RET_BODY.toString());
            JSONObject respParamsJson = JSONObject.parseObject(respParamsStr);
            String retSign = respParamsJson.remove("sign") + "";
            System.out.println("sign:" + retSign);

            // 验证平台签名   公钥
            //String publicKey = PayConfig.publicKey;
            String publicKey = PayConfig.publicKey;
            String toverify = SignUtils.getSignData(respParamsJson);
            System.out.println("待签名字符串：" + toverify);
            logger.info("待签名字符串：" + toverify);
            boolean signResult = SignUtils.verifyingSign(publicKey, retSign, SignUtils.getSignData(respParamsJson));
            System.out.println("验签结果：" + signResult);
            logger.info("验签结果：" + signResult);
            if (!signResult) {
                logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+"商户验平台签名失败，请检查公钥是否正确或者数据是否被篡改");
            	appResult.setMessage("FALL");
            	appResult.setCode("1");
                return appResult;
            } else {
            	// 通常意义上一次成功的通讯
                logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+respParamsJson);
//                crs.setSignDate(retSign);
                appResult = gzylredcord(respParamsJson.toJSONString(), false  , bodyInfo , sessionRole); // 处理返回数据
            }

        } catch (Exception e) {
            System.out.println("代付发生异常："+ e);
            logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+e.getMessage());
            appResult.setMessage(e.getMessage());
            appResult.setCode("1");
            return appResult;
        }
        return appResult;
	}

	/**
	 * 处理请求提现返回请求结果的数据
	 * @param reqMsg
	 * @param isQuery
	 * @param bodyInfo
	 * @param sessionRole
	 * @return
	 */
	private Result gzylredcord(String reqMsg, boolean isQuery, BodyInfo bodyInfo, String sessionRole ) {
		Result appResult = new Result();
		JSONObject respParamsJson = JSONObject.parseObject(reqMsg);
		String retCode = respParamsJson.remove("retCode") + "";
		MemberDrawcashRecord crs = memberDrawcashRecordMapper.selectByPrimaryKey(Long.valueOf(bodyInfo.getId()));
		String custOrderId = crs.getOrderNum();
		logger.info("贵州银联代付,返回结果判断方法中1,用户ID:"+crs.getMemberId()+",订单号:"+custOrderId+",请求返回状态:"+retCode);
		if(SystemRetCode.SUCCESS.toString().equals(retCode)){
			//直接扣钱
			updateDrawcashMoneyNum(Long.valueOf(bodyInfo.getId()));
			appResult.setMessage(retCode);
			appResult.setCode(crs.getAmount().toString());
		} else if ("FAIL".equals(retCode) ||  "TIMEOUT".equals(retCode) || "EXCPETION".equals(retCode)){
			System.out.println("交易关闭，交易失败");
			//修改打款记录状态
			crs.setStatus(3);//交易状态  1 申请 2 成功 3 失败
			crs.setTradeState("交易失败");
			crs.setUpdateTime(new Date());
			memberDrawcashRecordMapper.updateByPrimaryKeySelective(crs);
			logger.info("订单号:"+crs.getOrderNum()+",更新提现记录实体:"+crs);
			 //打款失败 把提现金额返回用户通权现金中
			 Long money = crs.getAmount().longValue();
			 Long user_id = Long.valueOf(crs.getMemberId()+"");
			appResult.setMessage(retCode);
			appResult.setCode(money.toString());
		} else {
			crs.setTradeState(retCode);
			logger.info("未知结果");
			memberDrawcashRecordMapper.updateByPrimaryKeySelective(crs);
			logger.info("贵州银联代付,返回结果判断方法中未知的返回,用户ID:"+crs.getOrderNum()+",订单号:"+crs.getMemberId()+",请求返回状态:"+retCode);
			appResult.setMessage("未知结果");
			appResult.setCode(crs.getAmount().toString());
		}
		return appResult;
	}

	/**
	 * 异步回调
	 * @param encReq
	 * @return
	 */
	@Transactional(rollbackFor=Exception.class)
	@Override
	public Result validation(String encReq) {
		Result appResult = new Result();
		ObjectMapper objectMapper = new ObjectMapper();
		logger.info("start处理回调数据开始，序列化密文为:"+encReq);
		try {
			encReq = (String) objectMapper.readValue(encReq, TypeFactory.rawClass(String.class));
		} catch (IOException e) {
			logger.info("反序列化失败");
			e.printStackTrace();
		}
		logger.info("start处理回调数据开始，反序列化密文为:"+encReq);
		JSONObject respJson = JSONObject.parseObject(encReq);
		String custOrderId = respJson.get("custOrderId") + "";
		String transStatus = respJson.get("transStatus") + "";
		
		if ("".equals(custOrderId) || custOrderId == null) {
			appResult.setMessage("statuserror");
			logger.info("回调方法执行中,订单号"+custOrderId+",接收回调参数异常");
			return appResult;
		}
		MemberDrawcashRecord crs =new MemberDrawcashRecord();
		try {
			crs = memberDrawcashRecordMapper.getMemberDrawcashRecord(custOrderId);
			if (crs==null) {
				appResult.setMessage("statuserror");
				logger.info("回调方法执行中,订单号"+custOrderId+",此订单未查询到");
				return appResult;
			}
			if (crs.getStatus()==null) {
				appResult.setMessage("statuserror");
				logger.info("回调方法执行中,订单号"+custOrderId+",此订单未查询到");
				return appResult;
			}
		} catch (Exception e1) {
			appResult.setMessage("statuserror");
			e1.printStackTrace();
			logger.info("回调方法执行中,订单号"+custOrderId+",此订单查询异常");
			return appResult;
		}
		Integer status = crs.getStatus();
		logger.info("回调方法执行中,订单号"+custOrderId+",此订单的状态:"+status);
		if (status!=0) {
			appResult.setMessage("statuserror");
			logger.info("回调方法执行中,订单号"+custOrderId+",此订单的状态:"+status+"不在回调执行范围内,返回statuserror");
			return appResult;
		}
		System.out.println("--------------贵州银联回调获取的参数-----------------"+respJson);
		/*if (!SystemRetCode.SUCCESS.toString().equalsIgnoreCase(transStatus)) {
        	logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+"通讯异常，请查看日志");
        	appResult.setMsg("statuserror");
            return appResult;
        }*/
		logger.info("回调方法执行中,"+"异步回调返回状态:"+transStatus+"流水号:"+custOrderId);
        System.out.println("----------------贵州银联回调获取的参数转换格式后-------------------------"+respJson);
        String retSign = respJson.remove("sign") + "";
        System.out.println("sign:" + retSign);
     // 验证平台签名   公钥
        //String publicKey = PayConfig.publicKey;
        String publicKey = PayConfig.publicKey;
        System.out.println("待签名字符串：" + SignUtils.getSignData(respJson));
        logger.info("待签名字符串：" + SignUtils.getSignData(respJson));
		try {
			boolean signResult = SignUtils.verifyingSign(publicKey, retSign, SignUtils.getSignData(respJson));
			System.out.println("验签结果：" + signResult);
	        logger.info("验签结果：" + signResult);
	        if (!signResult) {
	            logger.info(SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+"商户验平台签名失败，请检查公钥是否正确或者数据是否被篡改");
	            appResult.setMessage("statuserror");
	            System.out.println("验签失败");
	            return appResult;
	        } else {
	        	String reqMsg = respJson.toJSONString();
				appResult  = tradeCode(reqMsg,crs);//处理返回数据
	        }
	        
		} catch (Exception e) {
			System.out.println("代付发生异常："+ e);
            logger.info("代付发生异常："+SystemRetField.RET_CODE.toString()+SystemRetCode.COM_ERROR.toString()+SystemRetField.RET_DESC.toString()+e.getLocalizedMessage()+"====="+e.getMessage());
            appResult.setMessage("statuserror");
            return appResult;
		}
		return appResult;
	}

	/**
	 * 请求提现成功时，处理会员提现后余额更新--用于提交请求成功后马上执行，此时状态为处理中，但是要直接减掉用于余额(无论后面最终异步请求结果是否成功)
	 * @param id 会员提现记录表的id
	 */
	private void updateDrawcashMoneyNum(Long id){
		MemberDrawcashRecord memberDrawcashRecord = memberDrawcashRecordMapper.selectByPrimaryKey(Long.valueOf(id));
		Long memberid = memberDrawcashRecord.getMemberId();
		Long drawcash = memberDrawcashRecord.getAmount();
		Long fee = memberDrawcashRecord.getHandingCharge();
		String orderNum = memberDrawcashRecord.getOrderNum();//订单号

		//更新会员积分总流水记录表(先插入积分总流水记录表)
		ScoreTotalTrade scoreTotalTrade = new ScoreTotalTrade();
		scoreTotalTrade.setCreateTime(new Date());
		scoreTotalTrade.setOrderNo(orderNum);
		scoreTotalTrade.setMemberId(memberid);
		scoreTotalTrade.setScore(drawcash*TransCodeEnum.MEMBER_CASH.getMark());
		scoreTotalTrade.setFee(fee*TransCodeEnum.MEMBER_CASH.getMark());
		scoreTotalTrade.setTransCode(TransCodeEnum.MEMBER_CASH.getCode());
//		scoreTotalTradeMapper.addScoreTotalTrade(scoreTotalTrade);
		scoreTotalTradeMapper.insertUseGeneratedKeys(scoreTotalTrade);
		Long totalId = scoreTotalTrade.getId();
		logger.info("提现申请成功，新增总记录表返回主键："+totalId);
		//更新会员积分支出流水记录表
		ScoreCostTrade scoreCostTrade = new ScoreCostTrade();
		scoreCostTrade.setTransCode(TransCodeEnum.MEMBER_CASH.getCode());
		scoreCostTrade.setFee(fee*TransCodeEnum.MEMBER_CASH.getMark());
		scoreCostTrade.setScore(drawcash*TransCodeEnum.MEMBER_CASH.getMark());
		scoreCostTrade.setOrderNo(orderNum);
		scoreCostTrade.setSetId(totalId);
		scoreCostTrade.setMemberId(memberid);
		scoreCostTrade.setCreateTime(new Date());
		scoreCostTrade.setUpdateTime(new Date());
		scoreCostTradeMapper.addScoreCostTrade(scoreCostTrade);
		logger.info("提现申请成功，新增会员积分支出流水记录表，订单号："+orderNum);

		//更新会员积分基础表
		MemberScore memberScore = memberScoreMapper.getMemberScoreByMemberId(memberid.toString());
		Long enableScore = memberScore.getEnableScore();//可用积分
		Long drawcashScore = memberScore.getDrawcashScore();//提现积分
		BigDecimal enableSDB = BigDecimal.valueOf(enableScore);
		enableSDB = enableSDB.subtract(new BigDecimal(drawcash));//减去实际提现积分
		enableSDB = enableSDB.subtract(new BigDecimal(fee));//减去手续费，最终得到剩余可用积分
		BigDecimal drawcashSDB = BigDecimal.valueOf(drawcashScore);
		drawcashSDB = drawcashSDB.add(new BigDecimal(drawcash));//加上实际提现积分
		drawcashSDB = drawcashSDB.add(new BigDecimal(fee));//加上手续费
		memberScore.setUpdateTime(new Date());
		memberScore.setEnableScore(enableSDB.longValue());
		memberScore.setDrawcashScore(drawcashSDB.longValue());
		memberScoreMapper.updateByPrimaryKeySelective(memberScore);
		logger.info("提现申请成功，更新会员积分基础表信息，订单号："+orderNum);
		//更新提现记录状态
		memberDrawcashRecord.setTradeState("申请成功");//更新提现状态
		memberDrawcashRecordMapper.updateByPrimaryKeySelective(memberDrawcashRecord);
	}

	/**
	 * 异步后处理数据
	 * @param id
	 */
	private void updateMemberBalanceReturn(Long id,String transStatus){
		MemberDrawcashRecord memberDrawcashRecord = memberDrawcashRecordMapper.selectByPrimaryKey(id);
		String tradeState = memberDrawcashRecord.getTradeState();

		if(!("申请成功".equals(tradeState)||"提现处理中".equals(tradeState))){
			logger.info("提现订单已处理过，请勿重复处理");
			return;
		}
		if("FAIL".equals(transStatus)){
				//请求处理失败后，返回会员的钱和更新提现记录状态
				Long memberid = memberDrawcashRecord.getMemberId();
				Long drawcash = memberDrawcashRecord.getAmount();
				Long fee = memberDrawcashRecord.getHandingCharge();
				String orderNum = memberDrawcashRecord.getOrderNum();
				//更新会员积分总流水记录表(先插入积分总流水记录表)
				ScoreTotalTrade scoreTotalTrade = new ScoreTotalTrade();
				scoreTotalTrade.setCreateTime(new Date());
				scoreTotalTrade.setOrderNo(orderNum);
				scoreTotalTrade.setMemberId(memberid);
				scoreTotalTrade.setScore(drawcash);
				scoreTotalTrade.setFee(fee);
				scoreTotalTrade.setTransCode(TransCodeEnum.MEMBER_CASH.getCode());
//		scoreTotalTradeMapper.addScoreTotalTrade(scoreTotalTrade);
				scoreTotalTradeMapper.insertUseGeneratedKeys(scoreTotalTrade);
				Long totalId = scoreTotalTrade.getId();
				logger.info("异步请求失败，新增总记录表返回主键："+totalId);
				//更新会员积分支出流水记录表
				ScoreIncomeTrade scoreIncomeTrade = new ScoreIncomeTrade();
				scoreIncomeTrade.setTransCode(TransCodeEnum.MEMBER_CASH.getCode());
				scoreIncomeTrade.setFee(fee);
				scoreIncomeTrade.setScore(drawcash);
				scoreIncomeTrade.setOrderNo(orderNum);
//			scoreIncomeTrade.setSetId(totalId);
				scoreIncomeTrade.setMemberId(memberid);
				scoreIncomeTrade.setCreateTime(new Date());
				scoreIncomeTrade.setUpdateTime(new Date());
				scoreIncomeTradeMapper.addScoreIncomeTrade(scoreIncomeTrade);
				logger.info("异步请求失败，新增会员积分收入流水记录表，订单号："+orderNum);
				//更新会员积分基础表
				MemberScore memberScore = memberScoreMapper.getMemberScoreByMemberId(memberid.toString());
				Long enableScore = memberScore.getEnableScore();//可用积分
				Long drawcashScore = memberScore.getDrawcashScore();//提现积分
				BigDecimal enableSDB = BigDecimal.valueOf(enableScore);
				enableSDB = enableSDB.add(new BigDecimal(drawcash));//减去实际提现积分
				enableSDB = enableSDB.add(new BigDecimal(fee));//减去手续费，最终得到剩余可用积分
				BigDecimal drawcashSDB = BigDecimal.valueOf(drawcashScore);
				drawcashSDB = drawcashSDB.subtract(new BigDecimal(drawcash));//加上实际提现积分
				drawcashSDB = drawcashSDB.subtract(new BigDecimal(fee));//加上手续费
				memberScore.setUpdateTime(new Date());
				memberScore.setEnableScore(enableSDB.longValue());
				memberScore.setDrawcashScore(drawcashSDB.longValue());
				memberScoreMapper.updateByPrimaryKeySelective(memberScore);
				logger.info("异步请求失败，更新会员积分基础表信息，订单号："+orderNum);
				//更新会员提现记录，提现失败---
				memberDrawcashRecord.setStatus(2);//提现失败
				memberDrawcashRecord.setTradeState("提现失败");
				memberDrawcashRecord.setUpdateTime(new Date());
				memberDrawcashRecordMapper.updateByPrimaryKeySelective(memberDrawcashRecord);
		}else if(SystemRetCode.SUCCESS.toString().equals(transStatus)) {
			//更新会员提现记录，提现成功---
			logger.info("提现成功，更新提现记录状态");
			memberDrawcashRecord.setStatus(1);//提现成功
			memberDrawcashRecord.setTradeState("提现成功");
			memberDrawcashRecord.setUpdateTime(new Date());
			memberDrawcashRecordMapper.updateByPrimaryKeySelective(memberDrawcashRecord);
		}else {
			//更新会员提现记录,处理中---
			memberDrawcashRecord.setStatus(0);//提现处理中
			memberDrawcashRecord.setTradeState("提现处理中");
			memberDrawcashRecord.setUpdateTime(new Date());
			memberDrawcashRecordMapper.updateByPrimaryKeySelective(memberDrawcashRecord);
		}
	}

	/**
	 * 异步请求返回处理数据
	 * @param reqMsg
	 * @param crs
	 * @return
	 */
	private Result tradeCode(String reqMsg, MemberDrawcashRecord crs) {
		Result appResult=new Result();
		String FAIL = "FAIL";
		JSONObject jsonParam = JSONObject.parseObject(reqMsg);
		String transStatus = jsonParam.getString("transStatus");
		String custOrderId = jsonParam.getString("custOrderId");
		logger.info("交易结果处理方法中-处理交易结果,"+"异步回调返回状态"+transStatus+"流水号"+custOrderId);
		/*double cmoney = Double.valueOf(hmoney);
		double amoney = cmoney;
		DecimalFormat decimalFormat = new DecimalFormat("0.00000");
		String smoney = decimalFormat.format(amoney);*/
		if(SystemRetCode.SUCCESS.toString().equals(transStatus)){
			//修改打款记录状态 和 记录状态码
			System.out.println("交易成功");
			logger.info("交易成功    ========================="+reqMsg);
			updateMemberBalanceReturn(crs.getId(),transStatus);
			appResult.setMessage(SystemRetCode.SUCCESS.toString());
		} else if(FAIL.equals(transStatus)){
			//修改打款记录状态 打款失败
			//1、修改打款记录状态 和 记录状态码；2、退换用户提现金额
			updateMemberBalanceReturn(crs.getId(),transStatus);
			appResult.setMessage(transStatus);
		} else {
			System.out.println("等待支付结果，处理中");//需查询交易获取结果或等待通知结果
			updateMemberBalanceReturn(crs.getId(),transStatus);
			// 处理中业务逻辑
			logger.info("订单号:"+crs.getOrderNum()+",更新提现记录实体:"+crs);
			appResult.setMessage(transStatus);//正在处理
		}
		return appResult;
	}

}
